﻿using Microsoft.AspNetCore.Mvc;
using NET6.WebAPI.Extensions;

namespace NET6.WebAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class HttpClientController : ControllerBase
    {
        private readonly IHttpClientFactory _httpClientFactory;

        public HttpClientController(IHttpClientFactory httpClientFactory)
        {
            _httpClientFactory = httpClientFactory;
        }

        [HttpGet]
        public IActionResult Nonblocking()
        {
            Console.WriteLine("执行第一段代码");

            var client = _httpClientFactory.CreateClient();
            _ = client.GetAsync("https://example.com/api/data");

            Console.WriteLine("执行第二段代码");

            return Ok("操作完成");
        }
    }
}
